var express = require("express");
var app = express();
var fs = require("fs");
var count = 0;

app.use(express.static("public"));

if (fs.existsSync("./num.txt")) {
  count = fs.readFileSync("./num.txt", "utf-8");
}

app.get("/", function(req, res) {
  count++;
  fs.writeFileSync("./num.txt", count);
  res.send(html);
});

var html = `
<h1>林氏集团欢迎你</h1>
<form action="Visit" method="get">
    <button type="submit">访问量</button>
</form>
<button><a href="Recharge.html">充值</a></button>
`;


app.get("/Visit", function(req, res) {
  count = fs.readFileSync("./num.txt", "utf-8");
  console.log(count);
  res.send(`
  <h1>你是第${count}个访问者</h1>
  `);
});









app.get("/Rec", function(req, res) {
  var name = req.query.username;
  var pwd = req.query.password;
  var innum;
  if (!fs.existsSync("./incard.txt")) {
    fs.writeFileSync("./incard.txt");
  }

  innum = fs.readFileSync("./incard.txt", "utf-8");

  pass = JSON.stringify(fs.readFileSync("./card.txt", "utf-8"));
  // console.log(innum);
  // console.log(pass.includes(innum));
  if (pass.includes(pwd)) {
    if (inmun.includes(pwd) == true) {

      if (!fs.readFileSync("./incard.txt", "utf-8") == "") {
        fs.appendFileSync("./incard.txt", "," + pwd);
      } else {
        fs.writeFileSync("./incard.txt", pwd);
      }


      res.send("账号充值成功");
    } else {
      res.send("账号充值失败，密码已被使用");
    }
  } else {
    res.send("账号充值失败，密码错误");
  }
});

app.listen(5555, function() {
  console.log("服务器启动...");
});
